package com.globalwave.common.web;

import com.globalwave.base.BaseAction;
import com.globalwave.common.ArrayPageList;
import com.globalwave.common.entity.Catalog;
import com.globalwave.common.entity.CatalogCriterion;
import com.globalwave.common.service.CatalogService;
import com.opensymphony.xwork2.Preparable;

public class CatalogAction extends BaseAction implements Preparable {

    private static final long serialVersionUID = 8582051849254108462L;
    
    protected CatalogService catalogService ;
    protected Catalog catalog ;
    private Long user_id ;
    private Long organization_id ;
    private CatalogCriterion catalogCriterion ; 

    
    public String execute() throws Exception {    
        return this.list();    
    }
    
    public String list() throws Exception {      
        
        ArrayPageList<Catalog> pageList = 
            catalogService.query(catalogCriterion,pageIndex,pageSize,null) ;

        renderXML(pageList.asXML()) ;
        
        return null ;    
        
    }
    
    public String create()  throws Exception {              
        
        Object newCatalog = catalogService.create(catalog) ;

        renderXML(this.getSuccessCreateMessage(newCatalog).asXML()) ;
        
        return null;    
        
    }
    
    public String update()  throws Exception {     
        
        catalogService.update(catalog) ;

        renderXML(this.getSuccessUpdateMessage(catalog).asXML()) ;
        
        return null;    
        
    }
    
    public String delete()  throws Exception {
        if (this.ids == null) { 
            catalogService.delete(catalog) ;
        } else {
            catalogService.deleteAll(this.ids) ;
        }

        renderXML(this.getSuccessDeleteMessage().asXML()) ;
        
        return null;    
        
    }
    
    public void prepare() throws Exception {
        // TODO Auto-generated method stub
        
    }
    
    public void setCatalogService(CatalogService catalogService) {
        this.catalogService = catalogService;
    }


    public CatalogCriterion getCatalogCriterion() {
        return catalogCriterion;
    }

    public void setCatalogCriterion(CatalogCriterion catalogCriterion) {
        this.catalogCriterion = catalogCriterion;
    }

    public Long getUser_id() {
        return user_id;
    }

    public void setUser_id(Long user_id) {
        this.user_id = user_id;
    }

    public Long getOrganization_id() {
        return organization_id;
    }

    public void setOrganization_id(Long organization_id) {
        this.organization_id = organization_id;
    }

}
